package com.example.demo2.common.api.context;

import org.springframework.web.context.request.WebRequest;

import com.example.demo2.common.api.LqApi;

public class LqContext {
    private transient WebRequest request;

    private String token;
    private String method;

    public LqContext(WebRequest request, String method) {
        this.request = request;
        this.token = request.getHeader("token");
        this.method = method;
    }

    public WebRequest getRequest() {
        return request;
    }

    public String getToken() {
        return token;
    }

    public String getMethod() {
        return method;
    }

    public static void setContext(WebRequest webRequest, LqContext context) {
        webRequest.setAttribute(LqApi.RequestAttributes.CONTEXT, context, WebRequest.SCOPE_REQUEST);
    }

    public static LqContext getContext(WebRequest webRequest) {
        return (LqContext) webRequest.getAttribute(LqApi.RequestAttributes.CONTEXT, WebRequest.SCOPE_REQUEST);
    }

}
